﻿using System;
using System.Threading;
using System.Windows.Forms;

namespace AsicMonitor
{
    public partial class SpaceDailog : Form
    {
        public SpaceDailog(string spaceName)
        {
            InitializeComponent();

            Win32Utility.SetCueText(spaceNameTxt, "请输入矿场名字");
            if(spaceName != null && spaceName != "")
            {
                spaceNameTxt.Text = spaceName;
            }
        }

        private void saveBtn_Click(object sender, EventArgs e)
        {
            string newName = spaceNameTxt.Text;
            if(newName == null || newName == "")
            {
                MessageBoxEx.Show(this, "矿场名字不能为空");
                return;
            }

            OnSaveSpceNameEvent(newName);
            Close();
        }

        public delegate void SaveSpceNameEvent(string name);
        public event SaveSpceNameEvent saveSpceNameEvent;
        protected virtual void OnSaveSpceNameEvent(string name)
        {
            SaveSpceNameEvent newEvent = Volatile.Read(ref saveSpceNameEvent);//保持线程安全,保留一个备份
            if (newEvent != null)
            {
                newEvent(name);
            }
        }
    }
}
